home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
IWF12.ZIP
/
MODULES
/
RENDER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-20
|
14KB
|
448 lines
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROFIL3.C (PROFILE procedures)
AUTHOR(s): Craig Muller 1992
Decription:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <windows.h>
#pragma hdrstop
#include <stdio.h>
#include <string.h>
#include "iwf.h"
// Defines.
#define MODULENAME "Render"
#define CLASSNAME MODULENAME"Popup"
//=======================================
// Exported procedures.
//=======================================
long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
BOOL FAR PASCAL _export DP_Render(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
//-------------------------------------
// Private procedures.
//-------------------------------------
void CreateThermoPalEntry(PALETTEENTRY *peThermo);
static void render(HDC hDC,IMAGE *image);
// Flags
// Private variables.
static int resolutions[]={1,2,5,10};
static int polyres =3;
static int usecolor=TRUE;
static int usegrid =TRUE;
static HPALETTE hPalColor; // Handle to color scale palette
static HWND hWndRender=NULL; // Render user window handle.
static HINSTANCE hInst; // Application instance handle.
/*
---------------------------------------------------------------------
fb_setpalette()
~~~~~~~~~~~~~~~~
DESCRIPTION:
---------------------------------------------------------------------
*/
void fb_SetPaletteEntries(IMAGE *image,int iStart,int cEntries,PALETTEENTRY *pe)
{
int i;
for (i=0; i<cEntries; i++)
{
image->LUT[iStart+i].peRed = pe[i].peRed;
image->LUT[iStart+i].peGreen = pe[i].peGreen;
image->LUT[iStart+i].peBlue = pe[i].peBlue;
image->LUT[iStart+i].peFlags = pe[i].peFlags;
}
}
/*
--------------------------------------------------------------------------
Render()
~~~~~~~~
PROFILER STARTUP PROCESSING PROCEDURE.
This is called when the user selects this option from the main menu.
This procedure check to see if the popup window exists. If so it simply
passes focus to the window and returns since there is nothing more to do.
If it does not exist then it proceeds to create the popup window and menu
and displays it on the screen. The popup window acts like a sub-program
within the main program and receives messages from the main program.
--------------------------------------------------------------------------
*/
void Render(HWND hWndParent)
{
char msg[80];
WNDCLASS wc;
// If an instance exists then set focus to that instance and return.
if (IsWindow(hWndRender))
{
ShowWindow(hWndRender,SW_SHOW);
SetFocus(hWndRender);
return;
}
hInst = GetWindowWord(hWndParent,GWW_HINSTANCE);
// Register a new window class for the popup window.
if (!GetClassInfo(hInst,CLASSNAME,&wc))
{
memset(&wc,0,sizeof(WNDCLASS)); // Zero init structure.
wc.lpszClassName = CLASSNAME; // Name for CreateWindow.
wc.style = CS_SAVEBITS; // Extra style parameters.
wc.lpfnWndProc = (WNDPROC)WP_Render; // Func to get msgs
wc.hInstance = hInst; // App that owns the class
wc.hIcon = LoadIcon(hInst,MODULENAME);
wc.lpszMenuName = MODULENAME;
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
if (!RegisterClass(&wc)) // Initialize new window class.
{
char sz[80];
sprintf(sz,"RegisterClass() failure! -> %s",CLASSNAME);
MessageBeep(MB_ICONEXCLAMATION);
MessageBox(NULL,sz,NULL,MB_OK | MB_ICONEXCLAMATION);
return; // Exit on failure
}
}
// Window class is registered, now create an window from the class.
hWndRender = CreateWindow(CLASSNAME,MODULENAME,
WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX,
200,100,770,400,hWndParent,NULL,hInst,NULL);
if (hWndRender)
{
ShowWindow(hWndRender,SW_SHOW);
SetFocus(hWndRender);
}
else
{
sprintf(msg,"CreateWindow() failure! -> %s",CLASSNAME);
MessageBeep(MB_ICONEXCLAMATION);
MessageBox(NULL,msg,NULL,MB_OK | MB_ICONEXCLAMATION);
}
}
/*
---------------------------------------------------------------------
long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
Description:
Local Window Procedure for processing image analysis. This is
registered in the header module.h.
This procedure handles a subset of the Windows message loop for
processing input messages.
---------------------------------------------------------------------
*/
long far PASCAL _export WP_Render(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
{
IMAGE *image;
if (IsWindow(hWndSrc))
image = (IMAGE *)GetWindowWord(hWndSrc,2); // Get attached data set.
else
image = NULL;
switch (wMsg)
{
case WM_CREATE:
hWndMod = hWnd; // Make this module active.
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
}
break;
case WM_COMMAND:
if (!image)
{
MessageBox(NULL,"No image is selected.","Render Tool",MB_OK);
break;
}
switch (wParam)
{
case 110:
{
RECT rc;
HDC hDC;
hDC = GetDC(hWnd);
SelectPalette(hDC,hPalMain,FALSE); // Select palette into DC
RealizePalette(hDC); // Map to system palette.
GetClientRect(hWnd,&rc);
FillRect(hDC,&rc,GetStockObject(LTGRAY_BRUSH));
render(hDC,image); // Render the 3D profile.
ReleaseDC(hWnd,hDC);
}
break;
case 120:
CallDialogBox(hWnd,DP_Render,MODULENAME);
break;
}
break;
case WM_SETFOCUS: // FOCUS HAS BEEN SET.
if (FlashWindow(hWnd,TRUE))
FlashWindow(hWnd,TRUE); // Make this module active.
hWndMod = hWnd; // Make this module active.
BringWindowToTop(hWnd); // Bring this module to top.
InvalidateRect(hWnd,NULL,FALSE); // Invalidate this image.
UpdateWindow(hWnd); // Update this image.
break;
case WM_KILLFOCUS: // FOCUS HAS BEEN KILLED.
break;
case WM_DESTROY: // DESTROY WINDOW.
DeleteObject(hPalColor); // Delete color scale palette.
break;
default: // Pass on if unprocessed.
return(DefWindowProc(hWnd, wMsg, wParam, lParam));
}
lParam=lParam;
return(NULL);
}
void Project(int x,int y,int z,POINT *pt)
{
pt->x = 240 + x - y/2;
pt->y = y/2 - z/2;
}
/*
------------------------------------------------------------------------------
FUNCTION: void Render(HWND hWnd)
PURPOSE :
Transfers the contents to the display device for display.
COMMENTS:
------------------------------------------------------------------------------
*/
void render(HDC hDC,IMAGE *image)
{
int size,x,y,xoff,yoff;
BYTE r,g,b,z,z0,z1,z2,z3;
POINT pt[4];
HBRUSH hBrush,hOldBrush;
HPEN hPen,hOldPen;
ShowCursor(FALSE);
size=resolutions[polyres];
xoff = 3;
yoff = 375-240;
SelectObject(hDC,GetStockObject(BLACK_PEN));
Project( 0, 0, 0,&pt[0]); MoveTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
Project(511, 0, 0,&pt[0]); LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
Project(511,479, 0,&pt[0]); LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
Project( 0,479, 0,&pt[0]); LineTo(hDC,xoff+pt[0].x,yoff+pt[0].y);
Project( 0, 0, 0,&pt[0